package com.stylefeng.guns.common.dto.common;

import com.stylefeng.guns.core.exception.GunsExceptionEnum;
import lombok.ToString;

import java.util.Map;

/**
 * @author carloszhang
 * @param <T>
 */
@ToString
public class ResultData<T> {

    public static final ResultData SUCCESS_RESULT = new ResultData();
    private T data;
    private int status;
    private String message;
    private Map<String, Object> extField;

    public ResultData() {
    }

    public ResultData(T data) {
        this.data = data;
    }

    public ResultData(T data, Map<String, Object> ext) {
        this.data = data;
        this.extField = ext;
    }

    public ResultData(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public ResultData(GunsExceptionEnum exEnum) {
        this.status = exEnum.getCode();
        this.message = exEnum.getMessage();
    }

    public static <T> ResultData<T> createResult(T data) {
        return new ResultData<T>(data);
    }

    public static <T> ResultData<T> errorResult(GunsExceptionEnum exEunm) {
        return new ResultData<>(exEunm);
    }

    public static <T> ResultData<T> errorResult(int status, String message) {
        return new ResultData<>(status, message);
    }


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getExtField() {
        return extField;
    }

    public void setExtField(Map<String, Object> extField) {
        this.extField = extField;
    }
}
